import book.BookList;
import user.AdminUser;
import user.NormalUser;
import user.User;

import java.util.Scanner;

public class Main {

    //可以利用返回值的向上转型  达到发挥的一致性
    public static User login(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的姓名：");
        String name = scanner.nextLine();
        System.out.println("请输入你的身份：1-》管理员   0-》普通用户");
        int choice = scanner.nextInt();
        //先将用户创建为null
        User user = null;
        if(choice == 1){
            //管理员
            user = new AdminUser(name);
        }else{
            //普通用户
            user = new NormalUser(name);
        }
        return user;
    }

    public static void main(String[] args) {

        BookList bookList = new BookList();

        //将登录的用户存到user中
        User user = login();
        int choice = -1;
        while(choice != 0) {
            choice = user.menu();
            user.doOperation(choice, bookList);

            System.out.println(user);
//            System.out.println(choice);
        }
    }
}
